package com.wuad.platformwuad.module.study.xml;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

        public class FirstTest {
            public static void main(String[] args) {
                try {
                    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                    DocumentBuilder builder = factory.newDocumentBuilder();
                    Document doc = builder.newDocument();

                    // 创建根元素
                    Element root = doc.createElement("root");
                    doc.appendChild(root);

                    // 创建loop_num元素并设置值
                    Element loopNum = doc.createElement("loop_num");
                    loopNum.setTextContent("10"); // 假设我们要设置的值是10
                    root.appendChild(loopNum);

                    // 输出到标准输出
                    TransformerFactory transformerFactory = TransformerFactory.newInstance();
                    Transformer transformer = transformerFactory.newTransformer();
                    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                    transformer.transform(new DOMSource(doc), new StreamResult(System.out));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

